package com.example.sunnyweather.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.example.sunnyweather.R;

public class MySQLiteOpenHelper extends SQLiteOpenHelper {
    private Context context;

    public MySQLiteOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        this.context = context;
    }

    public MySQLiteOpenHelper(Context context, String name, int version) {
        super(context, name, null, version);
        this.context = context;
    }

    public MySQLiteOpenHelper(Context context, String name) {

        this(context, name, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("drop table if exists province");
        db.execSQL("drop table if exists city");
        db.execSQL("drop table if exists county");
        String createProvince = context.getResources().getString(R.string.createProvince);
        String createCity = context.getResources().getString(R.string.createCity);
        String createCounty = context.getResources().getString(R.string.createCounty);
        db.execSQL(createProvince);
        db.execSQL(createCity);
        db.execSQL(createCounty);


//        Toast.makeText(context, "数据库创建成功", Toast.LENGTH_SHORT).show();

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {


    }


}
